package com.zp.system.dubbo;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zp.system.api.RemoteBaseDictDataService;
import com.zp.system.api.entity.SysBaseDictData;
import com.zp.system.mapper.SysBaseDictDataMapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 操作日志记录
 *
 * @author zhang peng
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteBaseDictDataServiceImpl implements RemoteBaseDictDataService {

    private final SysBaseDictDataMapper baseDictDataMapper;

    @Override
    public List<SysBaseDictData> listNotExistBaseData (String type, List<String> collect) {
        List<SysBaseDictData> list = baseDictDataMapper.selectList(Wrappers.<SysBaseDictData>lambdaQuery()
                .eq(SysBaseDictData::getType, type)
                .notIn(CollectionUtil.isNotEmpty(collect), SysBaseDictData::getValue, collect)
                .orderByAsc(SysBaseDictData::getSort)
        );
        return list;
    }

    /**
     * 查询存在的字典数据
     *
     * @param collect
     * @return
     */
    @Override
    public List<SysBaseDictData> selectExistBaseData (List<String> collect) {
        return baseDictDataMapper.selectList(Wrappers.<SysBaseDictData>lambdaQuery()
                .in(CollectionUtil.isNotEmpty(collect), SysBaseDictData::getId, collect)
        );
    }
}
